package com.gibs.peixunapi.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import com.gibs.peixunapi.model.Comment;

@Repository
public interface CommentDao extends JpaRepository<Comment, Integer>, JpaSpecificationExecutor<Comment> {

	@Query("from Comment where content = ?1")
	List<Comment> find(String name);

	@Query("from Comment where content like ?1")
	List<Comment> findLike(String name);

	@Query(value = "select * from Comment limit ?, ?", nativeQuery = true)
	List<Comment> findPage(Integer offset, Integer size);

	@Query(value = "select * from Comment where content = ? limit ?, ?", nativeQuery = true)
	List<Comment> findPage(String name, Integer offset, Integer size);

	@Query(value = "select * from Comment where content like ? limit ?, ?", nativeQuery = true)
	List<Comment> findPageLike(String name, Integer offset, Integer size);

	@Query(value = "select count(*) from Comment where content = ?", nativeQuery = true)
	Long count(String name);

	@Query(value = "select count(*) from Comment where content like ?", nativeQuery = true)
	Long countLike(String name);
	
	@Query("from Comment order by id asc")
	List<Comment> findAllAsc();
}

